var StateLoader = function() {
    var _self = this;
    _self.STATES = {
        00: {url : "_parts/Logon.html"},
        10: {url : "_parts/1_Mixer/Edit.html"},
        11: {url : "_parts/1_Mixer/Daily.html"},
        12: {url : "_parts/1_Mixer/MaterialTimeReport.html"},
        13: {url : "_parts/1_Mixer/OverheadReport.html"},
        14: {url : "_parts/1_Mixer/Recipes.html"},
        20: {url : "_parts/2_Packaging/Overview.html"},
        21: {url : "_parts/2_Packaging/Daily.html"},
        22: {url : "_parts/2_Packaging/Output.html"},
        23: {url : "_parts/2_Packaging/Statistics.html"},
        24: {url : "_parts/2_Packaging/Changeovers.html"},
        25: {url : "_parts/2_Packaging/Material.html"},
        26: {url : "_parts/2_Packaging/EditChangeovers.html"},
        27: {url : "_parts/2_Packaging/Settings.html"},
        28: {url : "_parts/2_Packaging/Downtime.html"},
        30: {url : "_parts/3_Silos/Levels.html"},
        31: {url : "_parts/3_Silos/Reports.html"},
        40: {url : "_parts/4_Activities/LiveData.html"},
        41: {url : "_parts/4_Activities/MixersHistory.html"},
        42: {url : "_parts/4_Activities/PackagingLinesHistory.html"},
        43: {url : "_parts/4_Activities/Alarms.html"},
        50: {url : "_parts/5_Events/Overview.html"},
        60: {url : "_parts/6_Settings/Holidays.html"},
        61: {url : "_parts/6_Settings/Users.html"},
        62: {url : "_parts/6_Settings/GroupRights.html"},
        63: {url : "_parts/6_Settings/SystemParameters.html"},
        64: {url : "_parts/6_Settings/ProductionUsers.html"}
    };
    _self.DEFAULT_STATE = 10;
    _self.loadState = function(state) {
        /**
         * State je integer koji predstavlja kOd stanja. Za svaki slucaj parse:
         */
        state = parseInt(state);
        var url = _self.STATES[state].url + "?" + Math.random();
        $("#states_holder").load(url);
        return _self;
    };
    _self.loadTabs = function(state, callback) {
        var urlPart = "";
        if(state !== "00"){
            switch (parseInt(state / 10)) {
                case 1 :
                    urlPart = "1_Mixer";
                    break;
                case 2 :
                    urlPart = "2_Packaging";
                    break;
                case 3 :
                    urlPart = "3_Silos";
                    break;
                case 4 :
                    urlPart = "4_Activities";
                    break;
                case 5 :
                    urlPart = "5_Events";
                    break;
                case 6 :
                    urlPart = "6_Settings";
                    break;
            }
            $(".tabs").load("_parts/" + urlPart + "/Tabs.html?x=" + Math.random(), function() {
                if (callback) {
                    callback();
                }
            });
        }
        else{
            $(".tabs").html("<div class='tab'>Enter Credentials</div>");
        }
    };
    
    return this;
};